//
//  ImageGridCell.swift
//  GifUsage
//
//  Created by han on 2020/12/29.
//  Copyright © 2020 Ting Han. All rights reserved.
//

import UIKit

class ImageGridCell: UICollectionViewCell {
   
    var isEditing: Bool = false {
        didSet {
            iconImageView.isHidden = !isEditing
        }
    }
    
    var isMarked: Bool = false {
        didSet {
            if isMarked {
                iconImageView.image = UIImage(systemName: "checkmark.circle")
            } else {
                iconImageView.image = UIImage(systemName: "circle")
            }
        }
    }
    
    var thumbnailImage: UIImage! {
        didSet {
            imageView.image = thumbnailImage
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        commonInit()
    }
    
    private  func commonInit() {
        clipsToBounds = true
        contentView.addSubview(imageView)
        imageView.frame = contentView.bounds
        contentView.addSubview(iconImageView)
        iconImageView.frame = CGRect(x: contentView.bounds.width - 30, y: 0, width: 30, height: 30)
    }
    
    override func prepareForReuse() {
        super.prepareForReuse()
        imageView.image = nil
    }
    
    lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFill
        return imageView
    }()
    
    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFill
        imageView.image = UIImage(systemName: "checkmark.circle")
        imageView.isHidden = true
        return imageView
    }()
    
}

